package com.wenlin.myproduction.binder;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wenlin.myproduction.R;
import com.wenlin.myproduction.bean.ScheduleContentBean;
import com.wenlin.myproduction.util.Checker;
import com.wenlin.myproduction.util.UI;
import com.wenlin.myproduction.widget.ScheduleContentView;

import me.drakeet.multitype.ItemViewBinder;

/**
 * @author 文琳_377979485@qq.com
 * @time 2021/10/12 0012 下午 5:10
 * @desc 排班管理的右下方主体表格内容列表条目——排班列表条目
 */
public class ScheduleContentBinder extends ItemViewBinder<ScheduleContentBean, ScheduleContentBinder.ScheduleContentHolder> {

    @NonNull
    @Override
    protected ScheduleContentHolder onCreateViewHolder(@NonNull  LayoutInflater inflater, @NonNull  ViewGroup parent) {
        return new ScheduleContentHolder(inflater.inflate(R.layout.item_schedule_content, parent, false));
    }

    @Override
    protected void onBindViewHolder(@NonNull  ScheduleContentHolder holder, @NonNull  ScheduleContentBean item) {
        if (Checker.notNull(holder.scv)) {
            holder.scv.setData(item.getListsDTO());
            holder.scv.setIsEdit(item.isEdit());
            if (Checker.notNull(item.getListsDTO()) && Checker.hasList(item.getListsDTO().getSchedule_arr())) {
                ViewGroup.LayoutParams params = holder.scv.getLayoutParams();
                params.width = (int) (UI.getPx(R.dimen.wpx168) * (item.getListsDTO().getSchedule_arr().size() + 2));//这里的b168就是表格的一个单元格的宽度。后面的加2表示的是要多留出显示夜班数和上班时长的位置。
                holder.scv.setLayoutParams(params);
            }
        }
    }

    static class ScheduleContentHolder extends RecyclerView.ViewHolder {
        ScheduleContentView scv;

        public ScheduleContentHolder(@NonNull  View itemView) {
            super(itemView);
            scv = itemView.findViewById(R.id.scv);
        }
    }
}
